package com.duke.shaking.auth;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.androidquery.AQuery;
import com.duke.shaking.R;
import com.duke.shaking.TitleActivity;
import com.duke.shaking.net.AsyncHttpResponseWithResultHandler;
import com.duke.shaking.net.NetUtils;
import com.duke.shaking.register.Register2Activity;
import com.loopj.android.http.AsyncHttpClient;

public class PasswordRecoverActivity extends TitleActivity {
	
	private AQuery aQuery;
	private String mobile;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		this.aQuery = new AQuery(this);
	}

	@Override
	protected int getLayoutId() {
		// TODO Auto-generated method stub
		return R.layout.activity_password_recover;
	}

	@Override
	protected void onTitleInit() {
		initTitle(TITLE_BTN_EXIST | TITLE_BTN_BACK,
				R.string.back,
				TITLE_BTN_EXIST,
				R.string.submit,
				R.string.title_password_recover);
	}
	
	public void onRightBtn(View v) {
		//go(PasswordRecoverActivity.class);
		
		mobile = aQuery.id(R.id.edit_tel_no).getText().toString();
		if(mobile == null || mobile.trim().length() == 0) {
			toast(R.string.err_empty_telno);
			return;
		}
		
		AsyncHttpResponseWithResultHandler responseHandler = new AsyncHttpResponseWithResultHandler(){
			
        	@Override
			public void onResultSuccess(String response) {
				// TODO Auto-generated method stub
				super.onResultSuccess(response);
				
				Intent intent = new Intent();
				intent.putExtra("mobile", mobile);
				setResult(RESULT_OK, intent);
				finish();
				
			}

			@Override
			public void onResultFailure(String result) {
				// TODO Auto-generated method stub
				super.onResultFailure(result);
				
				toast(R.string.err_recover_password);
			}
        };
        
        AsyncHttpClient client = NetUtils.forgetPassword(this, responseHandler);
        if (client != null) {
        	showProgress(R.string.progress_recover_password, client, responseHandler);
        }
	}
	
	
}
